# -*- coding: UTF-8 -*-
# server_assets
# @File : Monster.py
# @Date : 2023-08-30
# @Author  : wuzhouhai
# @Desc:
import KBEngine
from KBEDebug import *
import time
from objects.Character import Character
import s_monster
import s_monsterSkillGroup
import s_skillProperty


class Monster(Character):
    """怪物类
    """

    def __init__(self, id=-1, name='', templateId=0, isWordBoss=0, matrixId=0, deathTimes=0):
        """初始化怪物类
        """
        data = s_monster.datas.get(templateId)
        Character.__init__(self, id, name)
        # 设置角色类型为怪物类型
        self.setCharacterType(Character.MONSTERTYPE)
        self.templateId = int(data['id'])
        self.formatInfo = {}
        self.matrixId = matrixId
        self.hordeType = 2
        self.worldBoss = isWordBoss
        self.deathtimes = deathTimes
        self.reateTime = time.time()
        self.initialiseToo(data)
        self.fightPower = 0

    def initialiseToo(self, data):
        """初始化怪物信息
            @param id: int 怪物主键id
        """
        self.formatInfo['templateId'] = data['id']
        self.formatInfo['name'] = data['name']
        self.formatInfo['level'] = data['level']
        self.formatInfo['profession'] = data['profession']
        self.formatInfo['maxHp'] = data['hp'] + self.deathtimes * data['deathTimesAddHpBase']
        self.formatInfo['maxMp'] = data['mp']
        self.formatInfo['hp'] = self.formatInfo['maxHp']
        self.formatInfo['mp'] = data['mp']
        self.formatInfo['attack'] = data['attack']
        self.formatInfo['attack_def'] = data['attack_def']
        self.formatInfo['mc_attack'] = data['mc_attack']
        self.formatInfo['mc_attack_def'] = data['mc_attack_def']
        self.formatInfo['sc_attack'] = data['sc_attack']
        self.formatInfo['hit'] = data['hit']
        self.formatInfo['dodge'] = data['dodge']
        self.formatInfo['cri'] = data['cri']
        self.formatInfo['toughness'] = data['toughness']
        self.formatInfo['criHarm'] = data['criHarm']
        self.formatInfo['immuneBuffId'] = data['immuneBuffId']
        self.formatInfo['monsterSkillGroup'] = data['monsterSkillGroup']

        self.calculateFightPower()

    def calculateFightPower(self):
        """计算战斗力"""
        attack = {4: self.formatInfo['attack'], 5: self.formatInfo['sc_attack'], 6: self.formatInfo['mc_attack']}.get(
            self.formatInfo['profession'], 0)
        defAtttack = self.formatInfo['attack_def'] + self.formatInfo['mc_attack_def']
        self.fightPower = int(
            attack * 8 + defAtttack * 4 + self.formatInfo['maxHp'] * 1 + self.formatInfo['maxMp'] * 0.5 +
            self.formatInfo['hit'] * 0.5 + self.formatInfo['dodge'] * 3.2 \
            + self.formatInfo['cri'] * 2.7 + self.formatInfo['toughness'] * 4)

    def setMonsterHp(self, hp):
        """设置怪物血量"""
        self.formatInfo['hp'] = hp

    def getMonsterHp(self):
        """获取怪物血量"""
        return self.formatInfo.get('hp', 0)

    def getMonsterMaxHp(self):
        """获取怪物血量"""
        return self.formatInfo.get('maxHp', 0)

    def getTempletId(self):
        """获取怪物模板ID"""
        return self.templateId

    def getHordeType(self):
        """获取阵营类型"""
        return self.hordeType

    def getMatrixId(self):
        """获取怪物的阵法ID"""
        return self.matrixId

    def setMatrixId(self, matrixId):
        """设置阵法的ID"""
        self.matrixId = matrixId

    def getFightData(self, direction, isAthletics=False, isWorldBoss=False):
        """获取怪物战斗数据"""
        fightdata = {}
        fightdata['chaId'] = self.baseInfo.id  # 角色的ID
        fightdata['chaName'] = self.formatInfo['name']  # 角色的昵称
        fightdata['chaLevel'] = self.formatInfo['level']  # 角色的等级
        fightdata['characterType'] = self.getCharacterType()  # 角色的类型  1:玩家角色 2:怪物 3:宠物
        fightdata['chaProfessionType'] = self.formatInfo['profession']  # 角色职业
        fightdata['figureType'] = self.formatInfo['templateId']
        fightdata['chaBattleId'] = self.matrixId  # 角色在战场中的位置id
        fightdata['chaDirection'] = direction  # (角色在战斗中的归属阵营)1--(主动方)玩家朝向右，朝向右。2(被动方)--玩家朝向左
        fightdata['luckAtk'] = 0  # 角色攻击幸运值
        fightdata['luckDef'] = 0  # 角色诅咒值
        fightdata['chaCurrentHp'] = self.formatInfo['hp']  # 角色当前血量
        fightdata['chaMaxHp'] = self.formatInfo['maxHp']  # 角色的最大血量s
        fightdata['chaCurrentMp'] = self.formatInfo['mp']  # 角色当前魔法值
        fightdata['chaMaxMp'] = 100  # 角色的最大魔法值
        fightdata['physicalAttack'] = self.formatInfo['attack']  # 角色的物理攻击
        fightdata['physicalAttackMax'] = self.formatInfo['attack']  # 角色的物理攻击
        fightdata['magicAttack'] = self.formatInfo['mc_attack']  # 角色的魔法攻击
        fightdata['magicAttackMax'] = self.formatInfo['mc_attack']  # 角色的魔法攻击
        fightdata['physicalDefense'] = self.formatInfo['attack_def']  # 角色的物理防御
        fightdata['physicalDefenseMax'] = self.formatInfo['attack_def']  # 角色的物理防御
        fightdata['magicDefense'] = self.formatInfo['mc_attack_def']  # 角色的魔法防御
        fightdata['magicDefenseMax'] = self.formatInfo['mc_attack_def']  # 角色的魔法防御
        fightdata['scAttack'] = self.formatInfo['sc_attack']  # 角色的道术攻击
        fightdata['scAttackMax'] = self.formatInfo['sc_attack']  # 角色的道术攻击
        fightdata['hitRate'] = self.formatInfo['hit']  # 角色的命中
        fightdata['critRate'] = self.formatInfo['cri']  # 角色的当前暴击率
        fightdata['toughness'] = self.formatInfo['toughness']  # 角色抗暴
        fightdata['dodgeRate'] = self.formatInfo['dodge']  # 角色的闪避几率
        fightdata['criHarm'] = self.formatInfo['criHarm']  # 角色的暴击系数
        fightdata['fightSpeed'] = 0  # 角色的攻速
        fightdata['ActiveSkillList'] = []
        fightdata['canBeDizziness'] = {False: 0, True: 1}.get(isWorldBoss)  # 是否免疫眩晕

        skillInfo = s_monsterSkillGroup.datas.get(self.formatInfo['monsterSkillGroup'], {})  # 角色的主动攻击技能
        if skillInfo:
            if skillInfo.get('skill1', 0) > 0 and skillInfo.get('skill1', 0) in s_skillProperty.datas.keys():
                fightdata['ActiveSkillList'].append(skillInfo.get('skill1', 0))
            if skillInfo.get('skill2', 0) > 0 and skillInfo.get('skill2', 0) in s_skillProperty.datas.keys():
                fightdata['ActiveSkillList'].append(skillInfo.get('skill2', 0))
            if skillInfo.get('skill3', 0) > 0 and skillInfo.get('skill3', 0) in s_skillProperty.datas.keys():
                fightdata['ActiveSkillList'].append(skillInfo.get('skill3', 0))
            if skillInfo.get('skill4', 0) > 0 and skillInfo.get('skill4', 0) in s_skillProperty.datas.keys():
                fightdata['ActiveSkillList'].append(skillInfo.get('skill4', 0))

        fightRowFormat = {1: 1, 2: 2, 3: 3, 4: 1, 5: 2, 6: 3}
        fightdata['fightRow'] = fightRowFormat.get(self.matrixId)  # 角色所在战斗行
        fightdata['canBeAttacked'] = 1  # 角色是否能被攻击
        fightdata['canAttacked'] = 1  # 角色是否能发动攻击
        fightdata['died'] = 0  # 是否死亡
        fightdata['canDoOrdSkill'] = 1  # 能否普通攻击
        fightdata['nextReleaseSkill'] = 0  # 下一条技能序号
        fightdata['canBeNotHurt'] = 0  # 是否免疫伤害
        fightdata['ordSkill'] = 10000000 + self.formatInfo['profession'] * 1000000  # 普通攻击ID 10000000+职业*1000000
        # fightdata['ActiveSkillList'].extend([fightdata['ordSkill'],fightdata['ordSkill']])#增加两次普通攻击
        fightdata['hurtGodAdd'] = 0  # 神属性增加攻击值百分比
        fightdata['magicDefGodAdd'] = 0  # 神属性增加魔防百分比
        fightdata['criHurtGodAdd'] = 0  # 神属性增加暴击伤害值百分比
        fightdata['physicalDefGodAdd'] = 0  # 神属性增加物防百分比
        fightdata['absorbHpGodAdd'] = 0  # 神属性增加生命吸取百分比
        fightdata['dodgeGodAdd'] = 0  # 神属性增加闪避百分比
        fightdata['recoverHpGodAdd'] = 0  # 神属性增加恢复生命百分比
        fightdata['expGodAdd'] = 0  # 神属性增加获取经验百分比
        fightdata['worldBoss'] = self.worldBoss  # 是否为世界BOSS
        fightdata['buffEffects'] = {}  # BUFF效果
        fightdata['qiangHunHurtPercent'] = 0
        fightdata['armor'] = 0  # 护甲
        fightdata['deHpRecover'] = 0  # 削弱生命恢复值
        fightdata['deHpRecoverPercent'] = 0  # 削弱生命恢复百分比
        fightdata['god'] = 0  # 无敌

        #         print u'怪物物理防御:%d-%d,怪物魔法防御:%d-%d'%(fightdata['physicalDefense'],fightdata['physicalDefenseMax'],fightdata['magicDefense'],fightdata['magicDefenseMax'])
        return fightdata

    def getFightPower(self):
        """获取战斗力"""
        return self.fightPower
